package cn.mhome.merchant.dao.jpa.clazz;


import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

import cn.mhome.merchant.dao.common.po.ClassType;

public interface ClassTypeDao extends JpaRepository<ClassType,Long>,ClassTypeDaoCustom{

	/**
	 * 查询有没有重复的记录
	 * @param classTypeId
	 * @param superClassId
	 * @param classTypeName
	 * @return
	 */
	@Query("SELECT COUNT(*) FROM ClassType ct WHERE ct.classTypeId <>:classTypeId AND ct.superClassId =:superClassId and ct.classTypeName =:classTypeName")
	Long findSameCount(@Param("classTypeId") long classTypeId, @Param("superClassId")long superClassId, @Param("classTypeName")String classTypeName);
	
	/**
	 * 查询有没有重复的记录
	 * @param superClassId
	 * @param classTypeName
	 * @return
	 */
	@Query("SELECT COUNT(*) FROM ClassType ct WHERE ct.superClassId =:superClassId and ct.classTypeName =:classTypeName")
	Long findSameCount(@Param("superClassId")long superClassId,@Param("classTypeName") String classTypeName);

	/**
	 * 查询一级分类
	 * @return
	 */
	@Query("FROM ClassType ct WHERE ct.superClassId = 0 ORDER BY createTime")
	List<ClassType> findSuperClassList();

}
